package com.changgou.order.listener;

import com.alibaba.fastjson.JSON;
import com.changgou.order.config.RabbitMQConfig;
import com.changgou.order.service.OrderService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class OrderPageListener {

    @Autowired
    private OrderService orderService;
    /**
     * 订单支付的监听器
     * @param message
     *      out_trade_no        订单Id
     *      transaction_id      微信的交易流水号
     */
    @RabbitListener(queues = RabbitMQConfig.ORDER_PAY)
    public void receiveMessage(String message){
        System.out.println("接收到order_pay消息队列的参数");
        Map<String,String> map = JSON.parseObject(message, Map.class);
        String out_trade_no = map.get("out_trade_no");
        String transaction_id = map.get("transaction_id");
        System.out.println("orderId : "+out_trade_no + " -- transactionId : "+transaction_id);

        //更新订单表的支付状态信息,插入订单日志
        orderService.updatePayStatus(out_trade_no,transaction_id);

    }
}
